package com.farmer.controller;

import com.farmer.pojo.Orders;
import com.farmer.service.OrdersService;
import com.farmer.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping("orders")
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("add")
    public Result add(@RequestBody Orders orders){
        Result result =ordersService.add(orders);
        return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        Result result = ordersService.delete(id);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Orders orders) {
        Result result = ordersService.update(orders);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = ordersService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
        Result result = ordersService.getAll();
        return result;
    }

    /*
     * 根据订单编号模糊查询*/
    @GetMapping("getByOrderIdLike")
    public Result getByOrderIdLike(@RequestParam String OrderId){
        Result result = ordersService.getByOrderIdLike(OrderId);
        return result;
    }

    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {

        Result result=ordersService.page(pageNum,pageSize);
        return result;
    }
/*
* 管理员端的发货操作*/
//    @PostMapping("shipOrder")
//    public Result shipOrder(@RequestParam Integer id){
//        Result result = ordersService.shipOrder(id);
//        return result;
//    }
/*
* 前台用户端的确认收货操作*/
//    @PostMapping("confirmReceipt")
//    public  Result confirmReceipt(@RequestParam Integer id){
//        Result result = ordersService.confirmReceipt(id);
//        return result;
//    }
    
  @GetMapping("getOrdersListByToken")
  public Result getOrdersListByToken(@RequestHeader String token){
    Result result = ordersService.getOrdersListByToken(token);
    return result;
}


}
